namespace WebCalendar.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class OtherTables : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Entries", "UserProfile_UserId", "dbo.UserProfile");
            DropIndex("dbo.Entries", new[] { "UserProfile_UserId" });
            CreateTable(
                "dbo.PersonalEntries",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        EntryBase_ID = c.Int(),
                        Category_ID = c.Int(),
                        UserProfile_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Entries", t => t.EntryBase_ID)
                .ForeignKey("dbo.Categories", t => t.Category_ID)
                .ForeignKey("dbo.UserProfile", t => t.UserProfile_UserId)
                .Index(t => t.EntryBase_ID)
                .Index(t => t.Category_ID)
                .Index(t => t.UserProfile_UserId);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Color = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.Calendars",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.CategoryFilters",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Visible = c.Boolean(nullable: false),
                        Category_ID = c.Int(),
                        Calendar_ID = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Categories", t => t.Category_ID)
                .ForeignKey("dbo.Calendars", t => t.Calendar_ID)
                .Index(t => t.Category_ID)
                .Index(t => t.Calendar_ID);
            
            CreateTable(
                "dbo.EntryFilters",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Visible = c.Boolean(nullable: false),
                        Entry_ID = c.Int(),
                        Calendar_ID = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.PersonalEntries", t => t.Entry_ID)
                .ForeignKey("dbo.Calendars", t => t.Calendar_ID)
                .Index(t => t.Entry_ID)
                .Index(t => t.Calendar_ID);
            
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                        Calendar_ID = c.Int(),
                        User_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Calendars", t => t.Calendar_ID)
                .ForeignKey("dbo.UserProfile", t => t.User_UserId)
                .Index(t => t.Calendar_ID)
                .Index(t => t.User_UserId);
            
            DropColumn("dbo.Entries", "UserProfile_UserId");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Entries", "UserProfile_UserId", c => c.Int());
            DropIndex("dbo.Roles", new[] { "User_UserId" });
            DropIndex("dbo.Roles", new[] { "Calendar_ID" });
            DropIndex("dbo.EntryFilters", new[] { "Calendar_ID" });
            DropIndex("dbo.EntryFilters", new[] { "Entry_ID" });
            DropIndex("dbo.CategoryFilters", new[] { "Calendar_ID" });
            DropIndex("dbo.CategoryFilters", new[] { "Category_ID" });
            DropIndex("dbo.PersonalEntries", new[] { "UserProfile_UserId" });
            DropIndex("dbo.PersonalEntries", new[] { "Category_ID" });
            DropIndex("dbo.PersonalEntries", new[] { "EntryBase_ID" });
            DropForeignKey("dbo.Roles", "User_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.Roles", "Calendar_ID", "dbo.Calendars");
            DropForeignKey("dbo.EntryFilters", "Calendar_ID", "dbo.Calendars");
            DropForeignKey("dbo.EntryFilters", "Entry_ID", "dbo.PersonalEntries");
            DropForeignKey("dbo.CategoryFilters", "Calendar_ID", "dbo.Calendars");
            DropForeignKey("dbo.CategoryFilters", "Category_ID", "dbo.Categories");
            DropForeignKey("dbo.PersonalEntries", "UserProfile_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.PersonalEntries", "Category_ID", "dbo.Categories");
            DropForeignKey("dbo.PersonalEntries", "EntryBase_ID", "dbo.Entries");
            DropTable("dbo.Roles");
            DropTable("dbo.EntryFilters");
            DropTable("dbo.CategoryFilters");
            DropTable("dbo.Calendars");
            DropTable("dbo.Categories");
            DropTable("dbo.PersonalEntries");
            CreateIndex("dbo.Entries", "UserProfile_UserId");
            AddForeignKey("dbo.Entries", "UserProfile_UserId", "dbo.UserProfile", "UserId");
        }
    }
}
